import getMessage from './S01'
import { People, Stu, Teacher, Cat } from './S02'
import { ArrayList, quickSort, stuOne, stuThree, stuTwo, stuType } from './S04'

//====== 函数重载 ======//
getMessage(1)
getMessage('audio', 1)

// ========类型断言&类型转换==========//
let people = new People()
let result1 = people as Stu // 类型断言 正确
let result2 = <Stu>people // 类型转换 正确
result1.study()
result2.eat()

let stu = new Stu('wangwu', 23, '北京', '123')
let result3 = stu as People // 正确
result3.eat()

const teacher = new Teacher()
const result4 = teacher as People
const result5 = people as Teacher
result4.eat()
result5.myusername

// 通过unknown/any突破限制😊
const cat = new Cat()
const newMan = cat as unknown as People

// =========泛型============ //
// let arrayList1 = new ArrayList<typeof stuOne>();
let arrayList1 = new ArrayList<stuType>()
arrayList1.add(stuOne)
arrayList1.add(stuTwo)
arrayList1.add(stuThree)
let stuobj = arrayList1.get(1)

// 泛型如果在使用时没有具体化的类型，并且定义泛型时使用了T=any，那么就会选择any数据类型
let arrayList2 = new ArrayList()
arrayList2.add(3)
arrayList2.add('abc')
arrayList2.add(stuOne)
arrayList2.get(0)
let stuObj2 = arrayList2.get(2)

// == 泛型函数 == //
var chineseArr = [3, 1, 8, 9, 20, 15, 2, 7, 13, 11, 19, 18, 5, 6, 17, 4]
let chineseArrSort = quickSort(chineseArr)
console.log('chineseArrSort:', chineseArrSort)

let strArr: Array<string> = ['cba', 'kkdf', 'ndf', 'bcdf', 'dfd', 'cdf']
let strArrSort = quickSort(strArr)
console.log('strArrSort:', strArrSort)
